package indi.zhifa.recipe.bailan.framework.auth.dao.service;

import com.alibaba.fastjson2.JSONObject;
import indi.zhifa.recipe.bailan.framework.auth.dao.IBaseUserRelevantDao;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.*;
import indi.zhifa.recipe.bailan.framework.common.entity.exception.ServiceException;

import java.util.List;

public interface IUserRelevantDao extends IBaseUserRelevantDao {
    UserEntity user_generate();
    UserEntity user_check(Long id);

    default UserEntity user_check(String pUserName){
        Long id = user_findByUserName(pUserName);
        if(null == id){
            throw new ServiceException("没有找到名为"+pUserName+"的用户");
        }
        return user_check(id);
    }

    default boolean user_existByName(String pUserName){
        Long id = user_findByUserName(pUserName);
        return null != id;
    }

    UserEntity user_save(BaseUserEntity pBaseUserEntity);
    UserEntity user_edit(Long pId, BaseUserEntity pBaseUserEntity);
    UserEntity user_removeById(Long pId);

    List<BaseRoleEntity> role_list();

    Long role_findByCode(String pCode);

    RoleEntity role_check(Long pId);

    default RoleEntity role_check(String pCode){
        Long id = role_findByCode(pCode);
        if(null == id){
            throw new ServiceException("不存在code为"+pCode+"的角色");
        }
        return role_check(id);
    }

    default boolean role_existByCode(String pCode){
        Long id = role_findByCode(pCode);
        return null != id;
    }

    RoleEntity role_save(BaseRoleEntity pBaseRoleEntity);

    RelUserRoleEntity relUserRole_generate();
    List<BaseRelUserRoleEntity> relUserRole_listByUserId(Long pUserId);
    boolean relUserRole_updateRoles(Long pUserId, List<BaseRelUserRoleEntity> relUserRoleEntityList);

    UserEntity user_load(JSONObject pUserCfg);

    RoleEntity role_load(JSONObject pRoleCfg);
}
